Completed
Push — master ( dc50e4...8acfd5 )
by
unknown
51s
created

utils.js ➔ getFullPath   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 1
dl 0
loc 4
rs 10
nop 3
1
import { uri } from 'unity-utils';
2
import { format } from 'url';
3
4
export function getAPIPrefix(APINamespace) {
5
    const reAbsolute = /^(\/|https?:\/\/)/ig;
6
    return reAbsolute.test(APINamespace) ? APINamespace : '/' + APINamespace;
7
}
8
9
export function getFullPath(APINamespace, namespace, path=[]) {
10
    path = [].concat(path);
11
    return uri.join(getAPIPrefix(APINamespace), namespace, ...path).replace(':/', '://');
12
}
13
14
export function formatURL(APINamespace = '', namespace = '', path=[], query={}) {
15
    return format({
16
        pathname: getFullPath(APINamespace, namespace, path),
17
        query: uri.query(query)
18
    });
19
}